﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Exhibition.Dao.ViewModel;
using Exhibition.Common.CacheManager;
using Exhibition.Common.Helper;
using System.Web; 
namespace Exhibition.Service
{
  public class BaseUserPage:BasePage
    {
      public UserModel LoginUser = null;

      protected override void OnInit(EventArgs e)
      {

          var userName = HttpContext.Current.User.Identity.Name;

          if (string.IsNullOrEmpty(userName))
          {

              Response.Redirect("../Login.aspx");

              //JsHelper.AlertAndRedirect(this, CommFunMsg.GetMessage("A0006", Lan.zh), ResolveClientUrl("~/Login.aspx"));

          }
          else
          {

              LoginUser = CommonCacheManager.GetCacheData<UserModel>("CurrentUser" + userName);

              if (LoginUser == null)
              {
                  LoginUser = CenterService.userService.GetByEMail(userName);
                  if (LoginUser != null)
                  {
                      CommonCacheManager.AddCacheData<UserModel>("CurrentUser" + userName, LoginUser, 60);

                  }
                  else
                  {
                      JsHelper.AlertAndRedirect(this, CommFunMsg.GetMessage("A0006", Lan.zh), ResolveClientUrl("~/Login.aspx"));
                     
                  }

              }
          }

          base.OnInit(e);
      }
    }
}
